// Main Entry Point - 主入口文件
// Augment Code 核心业务逻辑还原

import { AugmentCoreExtension } from './core-extension';
import { Logger, LogLevel } from './error-handling';

export { AugmentCoreExtension } from './core-extension';
export { 
    ToolExecutionCoordinator, 
    ToolExecutionFlowManager,
    ToolExecutionEvent,
    ToolExecutionRequest,
    ToolExecutionResponse
} from './tool-execution-coordinator';
export { 
    Logger, 
    LogLevel, 
    LogEntry,
    ErrorHandler, 
    ErrorCode, 
    ErrorDetails,
    AugmentError 
} from './error-handling';

// 重新导出工具库的核心接口
export {
    ToolManager,
    ToolRegistry,
    ToolExecutionEngine,
    ToolHandler,
    ToolResult,
    ToolExecutionContext,
    ToolDefinition,
    ToolCategory,
    ValidationResult
} from '@augment/tools';

// 重新导出聊天核心接口
export {
    ModelProvider,
    SendRequest,
    StructuredNode,
    NodeType,
    TurnStatus,
    Session
} from '@augment/chat-core';

// 重新导出聊天模型接口
export {
    createAnthropic
} from '@augment/chat-model';

/**
 * 创建 Augment 核心扩展实例的工厂函数
 */
export function createAugmentExtension(
    apiKey: string,
    modelName: string = 'claude-3-5-sonnet-20241022',
    logLevel: LogLevel = LogLevel.INFO
): AugmentCoreExtension {
    const logger = new Logger(logLevel);
    return new AugmentCoreExtension(apiKey, modelName, logger);
}

/**
 * 快速启动函数 - 创建并初始化扩展
 */
export async function quickStart(
    apiKey: string,
    options: {
        modelName?: string;
        logLevel?: LogLevel;
        enabledTools?: string[];
        workspaceRoot?: string;
    } = {}
): Promise<AugmentCoreExtension> {
    const {
        modelName = 'claude-3-5-sonnet-20241022',
        logLevel = LogLevel.INFO,
        enabledTools,
        workspaceRoot = process.cwd()
    } = options;

    const extension = createAugmentExtension(apiKey, modelName, logLevel);
    
    // 初始化扩展
    await extension.initialize();
    
    // 如果指定了启用的工具，禁用其他工具
    if (enabledTools) {
        const allTools = extension.getAvailableTools();
        for (const tool of allTools) {
            if (!enabledTools.includes(tool)) {
                extension.setToolEnabled(tool, false);
            }
        }
    }
    
    return extension;
}

/**
 * 版本信息
 */
export const VERSION = '1.0.0';

/**
 * 默认配置
 */
export const DEFAULT_CONFIG = {
    MODEL_NAME: 'claude-3-5-sonnet-20241022',
    LOG_LEVEL: LogLevel.INFO,
    MAX_CONCURRENT_TOOLS: 5,
    TOOL_TIMEOUT: 30000,
    MEMORY_FILE_NAME: '.augment-memories.json'
} as const;

/**
 * 支持的工具列表
 */
export const SUPPORTED_TOOLS = [
    // 文件操作工具
    'read-file',
    'save-file', 
    'str-replace-editor',
    
    // 进程管理工具
    'launch-process',
    'kill-process',
    'read-process',
    'write-process',
    'list-processes',
    
    // 记忆管理工具
    'remember',
    'memory-retrieval'
] as const;

/**
 * 工具类别
 */
export const TOOL_CATEGORIES = {
    FILE_OPERATIONS: 'FILE_OPERATIONS',
    PROCESS_MANAGEMENT: 'PROCESS_MANAGEMENT',
    MEMORY_MANAGEMENT: 'MEMORY_MANAGEMENT'
} as const;

// 默认导出
export default {
    AugmentCoreExtension,
    createAugmentExtension,
    quickStart,
    Logger,
    LogLevel,
    VERSION,
    DEFAULT_CONFIG,
    SUPPORTED_TOOLS,
    TOOL_CATEGORIES
};
